package ru.aptu.billing_client;

import ru.aptu.billing_message.*;

/**
 * Created by IntelliJ IDEA.
 * User: andrey
 * Date: 12/23/11
 * Time: 1:58 AM
 */

public class TestBillingClient {
    public static void main(String[] args) {
        System.setProperty("javax.net.ssl.trustStore", "src/main/resources/srvKeystore");
        System.setProperty("javax.net.ssl.trustStorePassword", "123456");

        BillingClient client = new BillingClient(Constants.PORT_NUM, Constants.SERVER_ADDRESS);
        if (!client.initConnection()) {
            System.err.println("Error connecting to billing server.");
            return;
        }

        System.err.println("Sending check protocol message");

        ResponseMessage message = client.sendMessage(new RequestMessage(BasicMessage.MessageType.CHECK_PROTOCOL));
        if (message == null) {
            System.err.println("null");
        } else {
            System.err.println(message.getStatus());
        }

        message = client.sendMessage(new AccountCheckMessage(BasicMessage.ServiceType.MOBILE_PHONE, "123"));
        if (message == null) {
            System.err.println("null");
        } else {
            System.err.println(message.getStatus());
        }

        message = client.sendMessage(new PaymentRequestMessage(BasicMessage.ServiceType.MOBILE_PHONE,
                "123", 13, 100, "RUB"));
        if (message == null) {
            System.err.println("null");
        } else {
            System.err.println(message.getStatus());
        }

        client.close();

    }
}
